<template>
	<view class="approve-modal" v-if="visible">
		<view class="cu-modal" :class="[visible==true?'show':'']">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">审批意见</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<!-- <view class="padding-xl" > -->
				<view class="cu-form-group statt-border" style="height: 300rpx;">
					<textarea maxlength="250" style="height: 100%;font-size: 30rpx;" v-model="remark" placeholder="请输入你的意见!"></textarea>
				</view>

				<!-- </view> -->
				<view class="cu-bar bg-white justify-end">
					<view class="action">
						<button class="cu-btn line-green text-gray" @tap="hideModal">取消</button>
						<button class="cu-btn bg-blue margin-left" @tap="submit">确定</button>

					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		submitZPFormData
	} from '../../../api/service.js'
	export default {
		data() {
			return {
				visible: false,
				remark: '',
				commentMsg: '',
				entityId: '',
				approve: 0,
				processId: ''

			}
		},
		methods: {
			hideModal() {
				this.remark = '';
				this.commentMsg = '';
				this.entityId = '';
				this.approve = 0;
				this.processId = '';
				this.visible = false;
				this.entityType='';
				
			},
			show(record) {
				console.log(record)
				this.visible = true;
				this.entityId = record.id;
				this.approve = record.approve;
				this.processId = record.processId;
                this.entityType=record.type;
			},
			submit() {
				console.log(this.remark)
				var _this=this;
				if(this.approve == 0 && this.remark.replace(/\s+/g,'') == ''){
					uni.showToast({
						title:'拒绝时候必须要填写意见！',
						duration:2000
					})
					return;
				}
			
				uni.showLoading({
				    title: '数据正在处理中....'
				});
				submitZPFormData({
					processId: this.processId,
					approve: this.approve,
					commentMsg: this.remark,
					entityId: this.entityId,
					entityType:this.entityType
				}).then(res=>{
					 uni.hideLoading();
					if(res.success){
						uni.showToast({
							title:'审批成功！',
							duration:1500,
							success:function() {
							   
								setTimeout(function(){
									uni.$emit('updateProInfo',{msg:'--'});
									uni.$emit('updateMount',{})
									uni.navigateBack({
										delta:1
									})
								},1500)
								_this.hideModal();
							}
						})
					}else{
					uni.showToast({
						title:'审批失败！',
						duration:1500
					})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.statt-border {
		border-bottom: 2rpx solid #F5F5F5;
		border-top: 2rpx solid #f5f5f5;
		text-align: left;
		line-height: 32rpx;
	}
</style>
